package com.neusoft.tijian.controller;

import com.neusoft.tijian.po.Doctor;
import com.neusoft.tijian.service.DoctorService;
import com.neusoft.tijian.config.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

/**
 * 医生控制器
 */
@RestController
public class DoctorController {

    @Autowired
    private DoctorService doctorService;

    /**
     * 医生登录接口
     * @param docCode 医生编码
     * @param password 登录密码
     * @param session 会话对象，用于存储登录状态
     * @return 统一响应结果
     */
    @PostMapping("/doctor/login")
    public Result login(
            @RequestParam String docCode,
            @RequestParam String password,
            HttpSession session) {

        // 调用服务层进行登录验证
        Doctor doctor = doctorService.login(docCode, password);

        if (doctor != null) {
            // 登录成功，将医生信息存入session
            session.setAttribute("doctor", doctor);
            return Result.success(doctor, "登录成功");
        } else {
            // 登录失败
            return Result.error("医生编码或密码不正确");
        }
    }
}
